﻿using Caliburn.Micro;
using SD.Common;
using SD.Infrastructure.DTOBase;
using SD.Infrastructure.WPF.Caliburn.Aspects;
using SD.Infrastructure.WPF.Caliburn.Base;
using SD.Infrastructure.WPF.Extensions;
using SD.Infrastructure.WPF.Models;
using SD.IOC.Core.Mediators;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ServiceModel.Extensions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using SlamDunk.MES.Client.ViewModels.ExecutionPlan;
using SlamDunk.MES.Client.ViewModels.Facility;
using SlamDunk.MES.Client.ViewModels.ProductionPlan;
using SlamDunk.MES.Client.ViewModels.StockOutOrder;
using SlamDunk.MES.IAppService.DTOs.Inputs;
using SlamDunk.MES.IAppService.DTOs.Outputs.PlanContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ResourceContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.StockContext;
using SlamDunk.MES.IAppService.Interfaces;
using SlamDunk.MES.Presentation.Maps;
using SlamDunk.MES.Presentation.Models.NotifyModels;
using SlamDunk.ValueObjects.Enums;

namespace SlamDunk.MES.Client.ViewModels.StockInOrder
{
    /// <summary>
    /// 入库单据添加ViewModel
    /// </summary>
    public class AddViewModel : ScreenBase
    {
        #region # 字段及构造器

        /// <summary>
        /// 库存单据服务契约接口代理
        /// </summary>
        private readonly ServiceProxy<IStockOrderContract> _iStockOrderContract;

        /// <summary>
        /// 资源定义服务契约接口代理
        /// </summary>
        private readonly ServiceProxy<IResourceContract> _iResourceContract;

        /// <summary>
        /// 基础定义服务契约接口代理
        /// </summary>
        private readonly ServiceProxy<IFoundationContract> _iFoundationContract;

        /// <summary>
        /// 编号生成服务契约接口代理
        /// </summary>
        private readonly ServiceProxy<INumberContract> _iNumberContract;

        /// <summary>
        /// 窗口管理器
        /// </summary>
        private readonly IWindowManager _windowManager;

        /// <summary>
        /// 依赖注入构造器
        /// </summary>
        public AddViewModel(ServiceProxy<IStockOrderContract> iStockOrderContract, ServiceProxy<IResourceContract> iResourceContract, ServiceProxy<IFoundationContract> iFoundationContract, ServiceProxy<INumberContract> iNumberContract, IWindowManager windowManager)
        {
            this._iStockOrderContract = iStockOrderContract;
            this._iResourceContract = iResourceContract;
            this._iFoundationContract = iFoundationContract;
            this._windowManager = windowManager;
            this._iNumberContract = iNumberContract;
        }

        #endregion

        #region 属性
        #region 单据编号
        /// <summary>
        /// 单据编号
        /// </summary>
        [DependencyProperty]
        public string Number { get; set; }
        #endregion

        #region 储存位置类型
        /// <summary>
        /// 储存位置类型
        /// </summary>
        [DependencyProperty]
        public IDictionary<string, string> StorageLocationTypes { get; set; }
        #endregion

        #region 库位列表
        /// <summary>
        /// 库位列表
        /// </summary>
        [DependencyProperty]
        public ObservableCollection<IdentiferNameNm> StorageLocations { get; set; }
        #endregion

        #region 单据类型列表
        /// <summary>
        /// 单据类型列表
        /// </summary>
        [DependencyProperty]
        public ObservableCollection<StockOrderClassInfo> StockOrderClassList { get; set; }
        #endregion

        #region 源单据类型
        /// <summary>
        /// 源单据类型
        /// </summary>
        [DependencyProperty]
        public IDictionary<string, string> SourceOrderTypes { get; set; }
        #endregion

        #region 源单据编号
        /// <summary>
        /// 源单据编号
        /// </summary>
        [DependencyProperty]
        public string SourceOrder { get; set; }
        #endregion

        #region 源单据Id
        /// <summary>
        /// 源单据Id
        /// </summary>
        [DependencyProperty]
        public string SourceOrderId { get; set; }
        #endregion

        #region 已选储存位置类型
        /// <summary>
        /// 已选储存位置类型
        /// </summary>
        [DependencyProperty]
        public StorageLocationType? SelectedStorageLocationType { get; set; }
        #endregion

        #region 已选库位列表
        /// <summary>
        /// 已选库位列表
        /// </summary>
        [DependencyProperty]
        public IdentiferNameNm SelectedStorageLocation { get; set; }
        #endregion

        #region 库位列表显示隐藏
        /// <summary>
        /// 库位列表显示隐藏
        /// </summary>
        [DependencyProperty]
        public Visibility StorageLocationComboBoxVisibility { get; set; }
        #endregion

        #region 库位描述显示隐藏
        /// <summary>
        /// 库位描述显示隐藏
        /// </summary>
        [DependencyProperty]
        public Visibility StorageLocationTextVisibility { get; set; }
        #endregion

        #region 库位描述
        /// <summary>
        /// 库位描述
        /// </summary>
        [DependencyProperty]
        public string StorageLocationText { get; set; }
        #endregion

        #region 已选源单据类型
        /// <summary>
        /// 已选源单据类型
        /// </summary>
        [DependencyProperty]
        public SourceOrderType? SelectedSourceOrderType { get; set; }
        #endregion

        #region 已选单据类型列表
        /// <summary>
        /// 已选单据类型列表
        /// </summary>
        [DependencyProperty]
        public StockOrderClassInfo SelectedStockOrderClass { get; set; }
        #endregion

        #region 描述
        /// <summary>
        /// 描述
        /// </summary>
        [DependencyProperty]
        public string Description { get; set; }
        #endregion

        #region 入库单据明细列表
        /// <summary>
        /// 入库单据明细集合
        /// </summary>
        [DependencyProperty]
        public ObservableCollection<StockInOrderDetailNm> DetailParams { get; set; }
        #endregion

        #region 工厂模型名称
        /// <summary>
        /// 工厂模型名称
        /// </summary>
        [DependencyProperty]
        public string FacilityName { get; set; }
        #endregion

        #region 工厂模型Id
        /// <summary>
        /// 工厂模型Id
        /// </summary>
        [DependencyProperty]
        public Guid? FacilityId { get; set; }
        #endregion

        #endregion

        #region 方法
        #region 初始化 —— override async Task OnInitializeAsync(CancellationToken cancellationToken)
        /// <summary>
        /// 初始化
        /// </summary>
        protected override async Task OnInitializeAsync(CancellationToken cancellationToken)
        {
            //初始化存储位置类型
            this.StorageLocationTypes = typeof(StorageLocationType).GetEnumMembers();
            //初始化源单据类型
            this.SourceOrderTypes = typeof(SourceOrderType).GetEnumMembers();
            //初始化单据类型列表
            PageModel<StockOrderClassInfo> StockOrderClassInfos = await Task.Run(() => this._iStockOrderContract.Channel.GetStockOrderClassesByPage(
                null, //关键字
                StockDirectionType.Input, //出/入库方向类型
                null, //是否生成条码
                null,//工厂模型Id
                1, //页码
                int.MaxValue));
            this.StockOrderClassList = new ObservableCollection<StockOrderClassInfo>(StockOrderClassInfos.Datas);
            //显示隐藏库位列表
            this.StorageLocationComboBoxVisibility = Visibility.Visible;
            this.StorageLocationTextVisibility = Visibility.Collapsed;
            DetailParams = new ObservableCollection<StockInOrderDetailNm>();
        }
        #endregion

        #region 清理源单据重选 —— async void ClearStock()
        /// <summary>
        /// 清理源单据重选
        /// </summary>
        public async void ClearStock()
        {
            SourceOrder = "";
            SourceOrderId = "";
        }
        #endregion

        #region 创建单据明细-弹出层 —— async void Create()
        /// <summary>
        /// 创建单据明细-弹出层
        /// </summary>
        public async void Create()
        {
            if (SelectedStorageLocationType == null)
            {
                MessageBox.Show("请选择储存位置类型！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SelectedStorageLocation == null)
            {
                MessageBox.Show("请选择储存位置！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            AddItemViewModel viewModel = ResolveMediator.Resolve<AddItemViewModel>();
            viewModel.Load(FacilityId);
            bool? result = await this._windowManager.ShowDialogAsync(viewModel);
            if (result == true)
            {
                CreateDetailParam(
                    viewModel.SelectedMaterial.Id, //物料定义Id
                    viewModel.SelectedMaterial.Name, //物料名称
                    viewModel.SelectedMaterial.Number,//物料编号
                    viewModel.materialLotId, //物料批次Id
                    viewModel.ProductionBatchNo, //物料批次
                    viewModel.SelectedSupplier?.Id,//供应商Id
                    viewModel.SelectedSupplier?.Name,//供应商名称
                    viewModel.ProducedDate, //生产日期
                   TimeSpan.FromDays(viewModel.GuaranteePeriod),//保质期
                    viewModel.ExpiredDate, //过期日期
                    viewModel.Specification,//规格
                    viewModel.Quantity, //数量
                    viewModel.Sort,//排序
                    viewModel.Description, //描述
                    viewModel.SelectedMaterialSourceType,
                    viewModel.ReceptionDate,
                    viewModel.SelectedMaterial.StandardUnitNo);
            }
        }
        #endregion

        #region 加载储存位置
        /// <summary>
        /// 加载储存位置
        /// </summary>
        public async void LoadStorageLocation()
        {
            this.Busy();

            await this.ReloadStorageLocation();

            this.Idle();
        }
        #endregion

        #region 加载源单据信息
        /// <summary>
        /// 加载源单据信息
        /// </summary>
        public async void LoadSourceOrder()
        {
            this.Busy();

            await this.ReloadSourceOrder();

            this.Idle();
        }
        #endregion

        #region 加载入库单编号
        /// <summary>
        /// 加载入库单编号
        /// </summary>
        public async void LoadStockOrderClass()
        {
            this.Busy();

            this.Number = await Task.Run(() =>
                      this._iNumberContract.Channel.GenerateStockOrderNo(
                         SelectedStockOrderClass.Number)//上级节点Id
                    );

            this.Idle();
        }
        #endregion

        #region 清空工厂模型 —— async void ClearFacility()
        /// <summary>
        /// 清空工厂模型
        /// </summary>
        public async void ClearFacility()
        {
            this.FacilityId = null;
            this.FacilityName = "";
        }
        #endregion

        #region 加载工厂模型-弹出层
        /// <summary>
        /// 加载工厂模型-弹出层
        /// </summary>
        public async void SelectFacility()
        {
            this.Busy();
            this.FacilityId = null;
            this.FacilityName = "";
            SelectFacilityViewModel viewModel = ResolveMediator.Resolve<SelectFacilityViewModel>();
            bool? result = await this._windowManager.ShowDialogAsync(viewModel);
            if (result == true)
            {
                FacilityId = viewModel.SelectedFacility.Id;
                FacilityName = viewModel.SelectedFacility.Name;
            }
            this.Idle();
        }
        #endregion

        #region 提交 —— async void Submit()
        /// <summary>
        /// 提交
        /// </summary>
        public async void Submit()
        {
            #region # 验证
            if (SelectedStockOrderClass == null)
            {
                MessageBox.Show("请选择单据类型！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SelectedStorageLocationType == null)
            {
                MessageBox.Show("请选择储存位置类型！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SelectedStorageLocationType == StorageLocationType.Description)
            {
                if (string.IsNullOrEmpty(StorageLocationText))
                {
                    MessageBox.Show("请输入库存位置！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            else
            {
                if (SelectedStorageLocation == null)
                {
                    MessageBox.Show("请选择库存位置！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            if (DetailParams.Count == 0)
            {
                MessageBox.Show("入库明细不能为空，至少需要一条数据！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            #endregion
            List<StockInOrderDetailParam> StockInOrderDetailParams = new List<StockInOrderDetailParam>();
            foreach (var detailParam in DetailParams)
            {
                MaterialLotParam materialLotParam = new MaterialLotParam();
                StockInOrderDetailParam stockInOrderDetailParam = new StockInOrderDetailParam();
                stockInOrderDetailParam.materialId = detailParam.MaterialId.Value;
                stockInOrderDetailParam.materialLotId = detailParam.MaterialLotId;
                stockInOrderDetailParam.quantity = detailParam.Quantity.Value;
                stockInOrderDetailParam.sort = detailParam.Sort;
                stockInOrderDetailParam.description = detailParam.Description;
                if (detailParam.SupplierId != null)
                {
                    materialLotParam.supplierId = detailParam.SupplierId.Value;
                    materialLotParam.productionBatchNo = detailParam.ProductionBatchNo;
                    materialLotParam.producedDate = detailParam.ProducedDate.Value;
                    materialLotParam.guaranteePeriod = detailParam.GuaranteePeriod.Value;
                    materialLotParam.expiredDate = detailParam.ExpiredDate.Value;
                    materialLotParam.receptionDate = detailParam.ReceptionDate.Value;
                    materialLotParam.specification = detailParam.Specification;
                    materialLotParam.materialSourceType = detailParam.MaterialSourceType.Value;
                    stockInOrderDetailParam.materialLotParam = materialLotParam;
                }
                StockInOrderDetailParams.Add(stockInOrderDetailParam);
            }

            this.Busy();
            //创建入库单据
            await Task.Run(() => this._iStockOrderContract.Channel.CreateStockInOrder(
                Number,//单据编号
                SelectedStockOrderClass.Id,//库存单据类Id
                SelectedSourceOrderType == null ? null : SelectedSourceOrderType,//源单据类型
                SourceOrderId,//源单据Id
                SourceOrder,//源单据名称
                SelectedStorageLocationType.Value,//目标储存位置类型
                SelectedStorageLocationType == StorageLocationType.Description ? StorageLocationText : SelectedStorageLocation.Id.ToString(),//目标储存位置Id
                SelectedStorageLocationType == StorageLocationType.Description ? StorageLocationText : SelectedStorageLocation.Name,//目标储存位置名称
                FacilityId,//工厂模型Id
                Description,//描述
                StockInOrderDetailParams));
            await base.TryCloseAsync(true);
            this.Idle();
        }
        #endregion

        #region 删除单据明细
        /// <summary>
        /// 删除单据明细
        /// </summary>
        public async void RemoveStockIn(StockInOrderDetailNm stockInOrderDetailNm)
        {
            this.Busy();
            //清除单据明细缓存
            DetailParams.Remove(stockInOrderDetailNm);
            this.Idle();
        }
        #endregion

        #region 创建单据明细 —— async Task CreateDetailParam()
        /// <summary>
        /// 创建单据明细
        /// </summary>
        /// <param name="materialId">物料定义Id</param>
        /// <param name="materialName">物料名称</param>
        /// <param name="materialNo">物料编号</param>
        /// <param name="materialLotId">物料批次Id</param>
        /// <param name="ProductionBatchNo">物料批次</param>
        /// <param name="supplierId">供应商Id</param>
        /// <param name="SupplierName">供应商名称</param>
        /// <param name="ProducedDate">生产日期</param>
        /// <param name="GuaranteePeriod">保质期</param>
        /// <param name="ExpiredDate">过期日期</param>
        /// <param name="Specification">规格</param>
        /// <param name="InitialQuantity">数量</param>
        /// <param name="sort">排序</param>
        /// <param name="description">描述</param>
        /// <param name="materialSourceType">物料来源</param>
        /// <param name="receptionDate">接收时间</param>
        /// <param name="standardUnitNo">单位</param>
        public void CreateDetailParam(Guid? materialId, string materialName, string materialNo, Guid? materialLotId, string ProductionBatchNo, Guid? supplierId, string SupplierName, DateTime? ProducedDate, TimeSpan? GuaranteePeriod, DateTime? ExpiredDate, string Specification, decimal InitialQuantity, int sort, string description, MaterialSourceType? materialSourceType, DateTime? receptionDate, string standardUnitNo)
        {
            this.Busy();
            //添加入库单明细参数模型
            DetailParams.Add(new StockInOrderDetailNm(
                materialId,
                materialName,
                materialNo,
                materialLotId,
                InitialQuantity,
                sort,
                description,
                null,
                supplierId,
                SupplierName,
                ProductionBatchNo,
                ProducedDate,
               GuaranteePeriod,
                ExpiredDate,
                receptionDate,
                Specification,
                materialSourceType,
                null,
                null,
                false,
                false,
                null,
                null,
                standardUnitNo
                ));
            this.Idle();
        }
        #endregion

        //Private
        #region 加载储存位置列表 —— async Task ReloadStorageLocation()
        /// <summary>
        /// 加载储存位置列表
        /// </summary>
        public async Task ReloadStorageLocation()
        {
            #region # 验证

            if (this.SelectedStorageLocationType == null)
            {
                this.StorageLocations = new ObservableCollection<IdentiferNameNm>();
                return;
            }
            #endregion

            //显示隐藏库位列表
            this.StorageLocationComboBoxVisibility = Visibility.Visible;
            this.StorageLocationTextVisibility = Visibility.Collapsed;
            switch (SelectedStorageLocationType)
            {
                case StorageLocationType.ProductionDomain://生产域
                    IEnumerable<IAppService.DTOs.Outputs.FoundationContext.FacilityInfo> Facilities = await Task.Run(() =>
                    this._iFoundationContract.Channel.GetFacilities(
                        null,//关键字
                        null,//工厂模型层次
                        FacilityType.ProductionDomain,//工厂模型类型
                        null)//上级节点Id
                    );
                    IEnumerable<IdentiferNameNm> Facilitiemodels = Facilities.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(Facilitiemodels);
                    break;
                case StorageLocationType.BusinessDomain://业务域
                    Facilities = await Task.Run(() =>
                    this._iFoundationContract.Channel.GetFacilities(
                        null,//关键字
                        null,//工厂模型层次
                        FacilityType.BusinessDomain,//工厂模型类型
                        null)//上级节点Id
                    );
                    Facilitiemodels = Facilities.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(Facilitiemodels);
                    break;
                case StorageLocationType.StorageDomain://储存域
                    Facilities = await Task.Run(() =>
                   this._iFoundationContract.Channel.GetFacilities(
                      null,//关键字
                      null,//工厂模型层次
                      FacilityType.StorageDomain,//工厂模型类型
                      null)//上级节点Id
                  );
                    Facilitiemodels = Facilities.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(Facilitiemodels);
                    break;
                case StorageLocationType.Person://人员
                    PageModel<PersonInfo> Persons = await Task.Run(() =>
                      this._iResourceContract.Channel.GetPersonsByPage(
                         null,//关键字
                         FacilityId,//工厂模型Id
                         null,//人员类Id
                         1,
                         int.MaxValue)//上级节点Id
                   );
                    IEnumerable<IdentiferNameNm> Personsmodels = Persons.Datas.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(Personsmodels);
                    break;
                case StorageLocationType.Team://班组
                    PageModel<TeamInfo> Teams = await Task.Run(() =>
                     this._iResourceContract.Channel.GetTeamsByPage(
                        null,//关键字
                        FacilityId,//工厂模型Id
                        1,
                        int.MaxValue)//上级节点Id
                  );
                    IEnumerable<IdentiferNameNm> TeamModels = Teams.Datas.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(TeamModels);
                    break;
                case StorageLocationType.Customer://客户
                    PageModel<EnterpriseInfo> Enterprises = await Task.Run(() =>
                    this._iResourceContract.Channel.GetEnterprisesByPage(
                       null,//关键字
                       EnterpriseType.Customer,//工厂模型Id
                       null,
                       1,
                       int.MaxValue)//上级节点Id
                 );
                    IEnumerable<IdentiferNameNm> EnterpriseModels = Enterprises.Datas.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(EnterpriseModels);
                    break;
                case StorageLocationType.Supplier://供应商
                    Enterprises = await Task.Run(() =>
                   this._iResourceContract.Channel.GetEnterprisesByPage(
                      null,//关键字
                      EnterpriseType.Supplier,//工厂模型Id
                      null,
                      1,
                      int.MaxValue)//上级节点Id
                );
                    EnterpriseModels = Enterprises.Datas.Select(x => x.ToIdentiferName());
                    StorageLocations = new ObservableCollection<IdentiferNameNm>(EnterpriseModels);
                    break;
                case StorageLocationType.Description://描述
                    StorageLocationComboBoxVisibility = Visibility.Collapsed;
                    StorageLocationTextVisibility = Visibility.Visible;
                    break;
            }
        }
        #endregion

        #region 加载源单据信息列表 —— async Task ReloadSourceOrder()
        /// <summary>
        /// 加载源单据信息列表
        /// </summary>
        public async Task ReloadSourceOrder()
        {
            #region # 验证

            if (this.SelectedSourceOrderType == null || this.SelectedSourceOrderType == null)
            {
                SourceOrder = "";
                SourceOrderId = "";
                return;
            }
            #endregion
            if (SelectedStorageLocationType == null)
            {
                MessageBox.Show("请选择储存位置类型！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SelectedStorageLocation == null)
            {
                MessageBox.Show("请选择储存位置！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SelectedSourceOrderType == null)
            {
                MessageBox.Show("请选择源单据类型！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            switch (SelectedSourceOrderType)
            {
                case SourceOrderType.OutboundOrder://出库单
                    SelectStockOutOrderViewModel viewModel = ResolveMediator.Resolve<SelectStockOutOrderViewModel>();
                    viewModel.Load(SelectedStorageLocationType, SelectedStorageLocation?.Id.ToString(), FacilityId);
                    bool? result = await this._windowManager.ShowDialogAsync(viewModel);
                    if (result == true)
                    {
                        var stockOutOrderInfo = viewModel.StockOutOrderList.Where(x => x.IsChecked == true).Select(x => x.Model).ToArray();
                        SourceOrder = stockOutOrderInfo.FirstOrDefault().Number;
                        SourceOrderId = stockOutOrderInfo.FirstOrDefault().Id.ToString();
                        var stockOrderDetailList = await Task.Run(() => this._iStockOrderContract.Channel.GetStockOrderDetails(Guid.Parse(SourceOrderId)));
                        foreach (var stockOrderDetailInfo in stockOrderDetailList)
                        {
                            CreateDetailParam(
                          stockOrderDetailInfo.MaterialId, //物料定义Id
                          stockOrderDetailInfo.MaterialInfo?.Name, //物料名称
                          stockOrderDetailInfo.MaterialInfo?.Number,//物料编号
                          stockOrderDetailInfo.MaterialLotId, //物料批次Id
                          stockOrderDetailInfo.MaterialLotInfo?.ProductionBatchNo, //物料批次
                          stockOrderDetailInfo.MaterialLotInfo?.SupplierId,//供应商Id
                          stockOrderDetailInfo.MaterialLotInfo?.SupplierName,//供应商名称
                          stockOrderDetailInfo.MaterialLotInfo?.ProducedDate, //生产日期
                          stockOrderDetailInfo.MaterialLotInfo?.GuaranteePeriod,//保质期
                          stockOrderDetailInfo.MaterialLotInfo?.ExpiredDate, //过期日期
                          stockOrderDetailInfo.MaterialLotInfo?.Specification,//规格
                          stockOrderDetailInfo.Quantity, //数量
                          stockOrderDetailInfo.Sort,//排序
                          stockOrderDetailInfo.Description, //描述
                          stockOrderDetailInfo.MaterialLotInfo?.MaterialSourceType,//物料来源
                          stockOrderDetailInfo.MaterialLotInfo?.ReceptionDate,//接收时间
                          stockOrderDetailInfo.MaterialInfo?.StandardUnitNo);//单位
                        }
                    }
                    break;
                case SourceOrderType.ExecutionPlan://作业计划
                    SelectExecutionPlanViewModel selectExecutionPlanViewviewModel = ResolveMediator.Resolve<SelectExecutionPlanViewModel>();
                    selectExecutionPlanViewviewModel.Load(false, null, null, false);
                    result = await this._windowManager.ShowDialogAsync(selectExecutionPlanViewviewModel);
                    if (result == true)
                    {
                        var ExecutionPlanInfo = selectExecutionPlanViewviewModel.ExecutionPlans.Where(x => x.IsChecked == true).FirstOrDefault();
                        SourceOrder = ExecutionPlanInfo.Model.Name;
                        SourceOrderId = ExecutionPlanInfo.Model.Id.ToString();
                    }
                    break;
                case SourceOrderType.ProductionPlan://生产计划
                    SelectProductionPlanViewModel selectProductionPlanviewModel = ResolveMediator.Resolve<SelectProductionPlanViewModel>();
                    selectProductionPlanviewModel.Load(false, null, null);
                    result = await this._windowManager.ShowDialogAsync(selectProductionPlanviewModel);
                    if (result == true)
                    {
                        Wrap<ProductionPlanInfo> productionPlanInfo = selectProductionPlanviewModel.ProductionPlans.Single(x => x.IsChecked == true);
                        SourceOrder = productionPlanInfo.Model.Name;
                        SourceOrderId = productionPlanInfo.Model.Id.ToString();
                    }
                    break;
            }
        }
        #endregion


        #endregion
    }
}
